#include <cstdio>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <cctype>
#include <set>

namespace uvu
{
#define LOCAL ____________DONT_DEFINE_ME____________
// #define ll long long
// #define inf 0x3f3f3f3f
#define int long long
#define inf 0x3f3f3f3f3f3f3f3fll
#define infll 0x3f3f3f3f3f3f3f3fll
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define gline debug("now is #%d\n", __LINE__)
#define pii std::pair <int, int>
#define mkp std::make_pair
#define fi first
#define se second
char _ST_;
const int BUFSIZE = (1 << 20);
char ibuf[BUFSIZE], *iS = ibuf, *iT = ibuf;
char obuf[BUFSIZE], *oS = obuf, *oT = obuf + BUFSIZE;
char getc()
{
#ifdef LOCAL
	return getchar();
#else
	if(iS == iT) iT = (iS = ibuf) + fread(ibuf, 1, BUFSIZE, stdin);
	return iS == iT ? EOF : *iS++;
#endif
#define getchar ERR
}

void Flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; }
struct Flusher { ~Flusher(){ Flush(); } }iamflusher;

void putc(char c)
{
#ifdef LOCAL
	putchar(c);
#else
	*oS++ = c;
	if(oS == oT) Flush();
#endif
#define putchar ERR
}

template <typename T = int> T read()
{
	T x = 0, f = 1; char c = getc();
	for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
	for(;  isdigit(c); c = getc()) x = (x << 3) + (x << 1) + (c ^ 48);
	return x * f;
}

template <typename T> void print(T x, char c)
{
static int sta[BUFSIZE], top;
	top = 0;
	if(x < 0) putc('-'), x = -x;
	if(!x) sta[top = 1] = 0;
	for(; x; x /= 10) sta[++top] = x % 10;
	for(; top; ) putc(sta[top--] ^ 48);
	if(c) putc(c);
}

int readstr(char *s, int base)
{
	int idx = base - 1; char c = getc();
	for(; !(isdigit(c) || isalpha(c) || c == '#' || c == '.'); c = getc());
	for(;   isdigit(c) || isalpha(c) || c == '#' || c == '.' ; c = getc()) s[++idx] = c;
	return idx - base + 1;
}

void printf(const char *s) { for(; *s; s++) putc(*s); }
template <typename T, typename ... Args>
void printf(const char *s, T x, Args ... rest)
{
	for(; *s; s++)
	{
		if(*s != '%') { putc(*s); continue; }
		s++; if(*s == 'd') print(x, 0);
		else if(*s == 'c') putc(x);
		printf(s + 1, rest ...);
		return;
	}
}

template <typename T> void ckmax(T &x, T y) { x = x > y ? x : y; }
template <typename T> void ckmin(T &x, T y) { x = x < y ? x : y; }
#define mod 998244353
// #define mod 1000000007
int sm(int x) { return x >= mod ? x - mod : x; }
void plus_(int &x, int y) { x = sm(x + y); }
void mul_(int &x, int y) { x = 1ll * x * y % mod; }
int ksm(int a, int b) { int res = 1; for(; b; b >>= 1, mul_(a, a)) if(b & 1) mul_(res, a); return res; }

#define N 1000010
int n, b[N], C;
std::vector <int> vec[N];
int dk[N], db[N];

struct Lish
{
	int sta[N], top;
	void ins(int x) { sta[++top] = x; }
	void build() { std::sort(sta + 1, sta + 1 + top); top = std::unique(sta + 1, sta + 1 + top) - sta - 1; }
	int lower(int x) { return std::lower_bound(sta + 1, sta + 1 + top, x) - sta; }
}X, Y;
std::vector <pii> nvec[N];
int ans = inf;
std::vector <int> vecans;
int cnt[N];

void solve()
{
	// memset(h, idx = -1, sizeof(h));
	n = read();
	for(int i = 1; i <= n; i++)
	{
		int sz = read();
		for(int j = 1; j <= sz; j++) vec[i].push_back(read());
	}
	C = read(); for(int i = 1; i <= n; i++) b[i] = read();
	for(int _ = 1; _ <= n; _++) if(!vec[_].empty())
	{
		int sz = vec[_].size();
		for(int x : vec[_]) Y.ins(x);
		for(int i = 0; i < sz - 1; i++)
		{
			int x = vec[_][i], y = vec[_][i + 1];
			X.ins(y - x + 1);
		}
	}
	X.ins(1); X.build(); Y.build();
	for(int _ = 1; _ <= n; _++) if(!vec[_].empty())
	{
		int sz = vec[_].size();
		nvec[1].push_back(mkp(Y.lower(vec[_][0]), 1));
		for(int i = 0; i < sz - 1; i++)
		{
			int x = vec[_][i], y = vec[_][i + 1], p = X.lower(y - x + 1);
			dk[1] += C, dk[p] -= C;
			db[p] += C * (y - x);
			nvec[1].push_back(mkp(Y.lower(y), 1));
			nvec[p].push_back(mkp(Y.lower(y), -1));
		}
		dk[1] += C;
	}
	int now = 0;
	for(int i = 1; i <= X.top; i++)
	{
		dk[i] += dk[i - 1];
		db[i] += db[i - 1];
		for(pii t : nvec[i])
		{
			now -= cnt[t.fi] * b[cnt[t.fi]];
			cnt[t.fi] += t.se;
			now += cnt[t.fi] * b[cnt[t.fi]];
		}
		int res = dk[i] * X.sta[i] + db[i] + now;
		// printf("i = %d, res += %d * %d + %d + %d\n", i, dk[i], X.sta[i], db[i], now);
		if(res < ans) vecans.clear();
		if(res <= ans)
		{
			vecans.push_back(X.sta[i]);
			ans = res;
		}
	}
	printf("%d %d\n", ans, (int)vecans.size());
	for(int x : vecans) print(x, ' ');
	putc('\n');
}

void init()
{

}

char _ED_;

void mian()
{
	debug("%.3f MB\n", abs(&_ST_ - &_ED_) / 1024.0 / 1024);
	init();
	for(int T = 1; T; solve(), T--);
}

#ifdef int
	#undef int
#endif
}

int main()
{
	freopen("list.in", "r", stdin);
	freopen("list.out", "w", stdout);
	uvu::mian(); return 0;
}